import React, {Component} from 'react';
import {StyleSheet, Text, View, Image, ScrollView} from 'react-native';
import {Button, WhiteSpace, WingBlank, Flex, Toast} from '@ant-design/react-native';
import {getAdvertInfo} from '~/api/advert';
import {getProjectNoticeInfo} from '~/api/project';
import moment from 'moment';
export default class CarouselInfo extends Component {
    static navigationOptions = {
        title: '公告详情',
    };
    constructor(props) {
        //调用基类的所有的初始化方法
        super(props);

        // 设置当前组件的属性
        this.state = {
            advertid: this.props.navigation.getParam('advertid') || 0,
            projectNoticeID: this.props.navigation.getParam('projectNoticeID') || 0,
            list: [],
        };
        if (this.state.advertid != 0) {
            getAdvertInfo({advert_id: this.state.advertid}).then((r) => {
                if (r.code === 0) {
                    this.setState({
                        list: r.data.data,
                    });
                } else {
                    Toast.info(r.msg);
                }
            });
        }
        if (this.state.projectNoticeID != 0) {
            getProjectNoticeInfo(this.state.projectNoticeID).then((r) => {
                if (r.code === 0) {
                    this.setState({
                        list: r.data,
                    });
                } else {
                    Toast.info(r.msg);
                }
            });
        }
    } //
    render() {
        return (
            <ScrollView style={{flex: 1, backgroundColor: 'white'}}>
                <WingBlank>
                    <Flex style={{margin: 10}}>
                        <Text>
                            {this.state.projectNoticeID != 0 && this.state.list.NoticeContent}{' '}
                            {this.state.advertid != 0 && this.state.list.AdvertContent}
                        </Text>
                    </Flex>
                    <Flex justify={'end'}>
                        <Text>发布时间：{moment(this.state.list.EditDateTime).format('YYYY-MM-DD HH:mm')}</Text>
                    </Flex>
                </WingBlank>
            </ScrollView>
        );
    }
}

const styles = StyleSheet.create({});
